import java.lang.Math;

public class ThreadSleepTester
{
    public static void main(String[] args)
    {
        TestThread t1 = new TestThread("线程1");
        TestThread t2 = new TestThread("线程2");
        TestThread t3 = new TestThread("线程3");

        t1.start();
        t2.start();
        t3.start();
    }
}

class TestThread extends Thread
{
    private int sleepTime;

    public TestThread(String name)
    {
        super(name);//为线程命名
        sleepTime = (int)(Math.random() * 6000);//获得随机休眠秒数
    }

    @Override
    public void run()
    {
        System.out.println(getName() + "going to sleep for " + sleepTime);

        try
        {
            Thread.sleep(sleepTime);
        }
        catch(InterruptedException i)
        {
            i.printStackTrace();
        }

        System.out.println(getName() + " finished");
    }
}
